package com.wj.blog;

import me.zhyd.houtu.Generator;
import me.zhyd.houtu.config.Config;

import java.io.File;


/**
 * @ClassName Generator
 * @Auther: wangjin
 * @Date: 2021/12/22/21:37
 * @Description: TODO
 * @Version 1.0
 */
public class GeneratorNew {

    public static void main(String[] args) {
        Config config = Config.getInstance()
                .setDriver("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://127.0.0.1:3306/wjblog?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false")
                .setUsername("root")
                .setPassword("123456");
        Config config1 = Config.getInstance()
                .setDriver("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://127.0.0.1:3306/wjblog?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false")
                .setUsername("root")
                .setPassword("123456");
        Config config2 = Config.getInstance()
                .setDriver("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://127.0.0.1:3306/wjblog?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false")
                .setUsername("root")
                .setPassword("123456");
        Config config3 = Config.getInstance()
                .setDriver("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://127.0.0.1:3306/wjblog?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false")
                .setUsername("root")
                .setPassword("123456");
        Config config4 = Config.getInstance()
                .setDriver("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://127.0.0.1:3306/wjblog?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false")
                .setUsername("root")
                .setPassword("123456");
        Config config5 = Config.getInstance()
                .setDriver("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://127.0.0.1:3306/wjblog?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true&useLegacyDatetimeCode=false")
                .setUsername("root")
                .setPassword("123456");

        ModuleConfig coreModuleConfig = ModuleConfig.builder()
                .basePackage("com.wj.blog")
                .templatePath("coreTemplate/")
                .outRootDir(path("blog_core"))
                .build();
        ModuleConfig coreMapperModuleConfig = ModuleConfig.builder()
                .basePackage("com.wj.blog")
                .templatePath("coreMapperTemplate/")
                .outRootDir(System.getProperty("user.dir") + File.separator + "blog_core" + File.separator + "src" +
                        File.separator + "main" + File.separator + "resources")
                .build();
        ModuleConfig pojoModuleConfig = ModuleConfig.builder()
                .basePackage("com.wj.blog")
                .templatePath("modelTemplate/")
                .outRootDir(path("blog_model"))
                .build();
        ModuleConfig interfaceModuleConfig = ModuleConfig.builder()
                .basePackage("com.wj.blog")
                .templatePath("interfaceTemplate/")
                .outRootDir(path("blog_interface"))
                .build();
        ModuleConfig adminModuleConfig = ModuleConfig.builder()
                .basePackage("com.wj.blog")
                .templatePath("adminTemplate/")
                .outRootDir(path("blog_admin"))
                .build();
        ModuleConfig webModuleConfig = ModuleConfig.builder()
                .basePackage("com.wj.blog")
                .templatePath("webTemplate/")
                .outRootDir(path("blog_web"))
                .build();


        Generator coreGenerator = generateBlogConfig(config, coreModuleConfig);
        coreGenerator.generate("sys_role", "sys_role_api");
        Generator coreMapperGenerator = generateBlogConfig(config1, coreMapperModuleConfig);
        coreMapperGenerator.generate("sys_role", "sys_role_api");
        Generator pojoGenerator = generateBlogConfig(config2, pojoModuleConfig);
        pojoGenerator.generate("sys_role", "sys_role_api");
        Generator interfaceGenerator  = generateBlogConfig(config3, interfaceModuleConfig);
        interfaceGenerator.generate("sys_role", "sys_role_api");
        Generator adminGenerator  = generateBlogConfig(config4, adminModuleConfig);
        adminGenerator.generate("sys_role", "sys_role_api");

//        Generator webGenerator  = generateBlogConfig(config5, webModuleConfig);
//        webGenerator.generate("sys_role", "sys_role_api");

//        generator.deleteOutRootDir();
        String[] tableArr = new String[]{
                "sys_role", "sys_role_api"
        };
        //"sys_api","sys_menu","sys_role","sys_role_api","sys_role_menu","sys_role_menu","user_info"



    }

    /**
     * 生成模块代码
     */
    public static Generator generateBlogConfig(Config config, ModuleConfig moduleConfig) {
        config.setTemplatePath(moduleConfig.getTemplatePath())
                .setBasePackage(moduleConfig.getBasePackage())
                .setOutRootDir(moduleConfig.getOutRootDir());
        return new Generator(config);
    }


    private static String path(String path) {
        return System.getProperty("user.dir") + File.separator + path + File.separator + "src" +
                File.separator + "main" + File.separator + "java" + File.separator + "com"
                + File.separator + "wj" + File.separator + "blog";
    }
}
